#!/bin/bash

# Set lock file path to this script dir
LOCKFILE="$(dirname "$PWD/$0")/.lock"

removelockfile() {
    rm -f "$LOCKFILE";
}

# Remove lock file on exit under any circumstances
trap removelockfile EXIT

while test -f "$LOCKFILE"; do echo "locked, waiting (delete $LOCKFILE if stuck)"; sleep 1; done
touch "$LOCKFILE"
git submodule update --init $1 || git submodule update --init --recursive $1
